Q: We use AppendMenu to create pop-up menus of
user-defined objects. The objects are named by the user. We have a
"menu resource stub" which we load, append to, and subsequently
dispose of, when the user clicks in the appropriate location. However,
there's a problem with this strategy. AppendMenu strips
meta-characters, which it recognizes as instructions for determining
menu characteristics such as command key equivalents or styles. Is
there any way in which we can ask AppendMenu to ignore
such characters?
A: If the Menu Manager function AppendMenuItemText is
available, use it. (It was introduced in Mac OS 8.5 along with
InsertMenuItemText .)
If not, the following code should help:
menu = GetMenuHandle (kSomeMenu);
AppendMenu (menu, "\pscratch");
SetMenuItemText (menu, CountMenuItems (menu), "\psome / text");
|
This works in all cases but one relatively obscure one. SetMenuItemText sets the menu item text just as requested. However,the standard menu definition
function ('MDEF' ) interprets any item with a leading hypen as a divider. To overcome this obstacle, prepend a 0 byte to the string before calling SetMenuItemText . This byte will not result in anything being drawn in the menu item, but will fool the MDEF into doing what you want.
Further Reference:
Inside Macintosh: Menu Manager
[Dec 22 1998]
|